package cn.wolfcode.wolf2w.util;

import cn.wolfcode.wolf2w.query.QueryObject;
import org.springframework.data.domain.*;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

public abstract class DBHelper {
    public static <T> Page<T>  query(MongoTemplate template, Pageable page, Query query, Class<T> clz, QueryObject qo){
        //查询总数据量
        long count = template.count(query, clz);
        if(count==0){
            return Page.empty();
        }
        //分页条件添加到查询对象上
        query.with(page);
        //执行查询
        List<T> list = template.find(query, clz);

        return new PageImpl<>(list,page,count);
    }
}
